#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/1/23 22:47
# @Author  : FLC
# @Contact : beifeng107@foxmail.com
# @File    : file_tool.py
# @Software: PyCharm
import os.path
import yaml


class FileTool:
    """
    封装对数据文件读写的操作
    """

    @classmethod
    def get_project_dir(cls):
        """
        获取项目的绝对路径
        :return: 该项目的绝对路径
        """
        return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    @classmethod
    def read_yaml(cls, file_name):
        """
        读取 yaml 文件
        :param file_name: 不带后缀的文件名称
        :return: yaml文件读取后的字典
        """
        file_path = os.sep.join([cls.get_project_dir(), "datas", file_name+".yaml"])
        with open(file_path, encoding="utf8") as f:
            return yaml.safe_load(f)